> Program: SCROLL-2 - Visual Basic Demo Code > Written By: Paul T. Dawson, P.O. Box 682, Chincoteague, VA, 23336 > Summary: VB 2.0 or 3.0 sample code that demonstrates "form scrolling". No VBX controls required. No API calls required. No cost (free!). > Requirements: To run the SCROLL-2.EXE file - Windows 3.1 and VBRUN200.DLL. To use the sample code - Visual Basic 2.0 or higher. > Limitation: This program will not display properly under Windows 3.0. > Design Goals: 1. Make a resizable form, with scroll bars to move around a large area. 2. Use the minimum amount of code. 3. Use default values wherever possible. 4. Add lots of comments! > File List: SCROLL-2.TXT - This File (no margins or page breaks). SCROLL-2.MAK - Visual Basic Project. SCROLL-2.FRM - Visual Basic Form (MDI main form). SCROLL-X.FRM - Visual Basic Form (MDI child form). SCROLL-2.FRX - Visual Basic Graphics (just one little icon). SCROLL-2.EXE - Finished EXE file. > Design Summary: This program uses a MDI form as the main form. It has one "MDI child" form, which is the "container" for all of the controls. Since the ScrollBars property of the main form is True, Visual Basic automatically handles all of the scroll bar positioning. The user can resize and/or scroll, and without any extra code, VB moves everything around perfectly! The Child form has no caption bar, so it looks exactly like an empty picture box. It can be many times larger than the screen, and any control can be placed anywhere on it. After setting all of the various properties at design time, the program is activated with ONE LINE of code: frmScroll.show After that line, VB does everything else in the scrolling department! > Details About Objects: 1. frmMain: The main form is a MDI (Multiple Document Interface) form. Everything on the form is default, except the caption and the ScrollBars property (true). 2. frmScroll: This is the scrolling form, and it can be any size, up to about 32,000 pixels square. The MinButton, MaxButton, and ControlBox properties are all set to False. Also, the BorderStyle is 0 (none), and when the program runs, the Caption is set to "" (null), and then the form will have NO title bar. It will just be one plain empty box! Also, the MDIChild property is set to True. This is critical! Setting those six properties correctly is the key to this program!!! 3. picMenuBar: This is on frmMain, and it has the default Align property of 1, which is "Align Top". This means that it is "glued" to the top of the MDI form, and it will stretch automatically when you resize it. This is the usual place to put a bunch of menu buttons - in this sample program, there is just one button. The picMenuBar control is not necessary for the form scrolling! However, when you are scrolling a giant form around, it's convenient to have something that is always visible - like picMenuBar. 4. cmdExit: This is the only control on picMenuBar. At design time, it's just a random size, but when the program runs, it expands to fill all of picMenuBar. Whenever you resize the main form, picMenuBar will always automatically resize. Then Sub picMenuBar_Resize is called to fix the size of cmdExit. 5. cmdStart: When you click this, everything starts to happen! This button was added for the convenience of people without VB who just want to try the EXE file. It just makes things more interesting to see all of the controls before they are resized and duplicated. 6. cmdHome(0 to 15): These are some extra non-critical controls that I added to frmScroll, to make the scrolling more visible. For a "real" program, these would all be replaced with "real" controls that actually did something. Actually, in this program, these buttons move the scrolling form back up to the starting location in the upper left hand corner of frmMain. At design time, there is only one cmdHome button. Its Index property is set to 0 (zero), and then at run time, 15 copies are created. > Miscellaneous Notes: 1. In this program, frmScroll is resized when the program runs. If you are designing a scrolling form that's SMALLER than your screen, then it may be easier to size it, and put all of the controls in the right places, all at design time. You can't do that if the form will be LARGER than your screen. If that's the case, you have to use code to resize the form and move all of the controls to the right locations. 2. Remember, any type of control can be placed onto the frmScroll form!!! 3. With AutoRedraw=False, I have successfully tested this up to 32,000 by 32,000 pixels, the equivalent of 3,333 standard VGA screens. That's over one BILLION pixels! When the size gets closer to 32,767, things start to get flakey. VB won't make a form larger than that number, which is equal to (2^15)-1. However, even though the form can be 32,767, I found that there were problems positioning the controls at positions over 32,000. That's why I suggest 32,000 as the maximum dimension. 32,000 pixels by 32,000 pixels is over 800 square feet - all on one big scrolling form. 4. Please experiment on non-critical projects first! /**** - <10-29-93> - ****/